package asia.lics.web.controller.system;


import asia.lics.common.annotation.Log;
import asia.lics.common.core.controller.BaseController;
import asia.lics.common.core.domain.AjaxResult;
import asia.lics.common.core.page.TableDataInfo;
import asia.lics.common.enums.BusinessType;
import asia.lics.common.utils.poi.ExcelUtil;
import asia.lics.system.domain.SysVipPackage;
import asia.lics.system.service.ISysVipPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * VIP套餐Controller
 *
 * @author ss-tutor
 * @date 2024-12-01
 */
@RestController
@RequestMapping("/system/package")
public class SysVipPackageController extends BaseController {
    @Autowired
    private ISysVipPackageService sysVipPackageService;

    /**
     * 查询VIP套餐列表
     */
    @PreAuthorize("@ss.hasPermi('system:package:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVipPackage sysVipPackage) {
        startPage();
        List<SysVipPackage> list = sysVipPackageService.selectSysVipPackageList(sysVipPackage);
        return getDataTable(list);
    }

    /**
     * 导出VIP套餐列表
     */
    @PreAuthorize("@ss.hasPermi('system:package:export')")
    @Log(title = "VIP套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysVipPackage sysVipPackage) {
        List<SysVipPackage> list = sysVipPackageService.selectSysVipPackageList(sysVipPackage);
        ExcelUtil<SysVipPackage> util = new ExcelUtil<SysVipPackage>(SysVipPackage.class);
        util.exportExcel(response, list, "VIP套餐数据");
    }

    /**
     * 获取VIP套餐详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:package:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysVipPackageService.selectSysVipPackageById(id));
    }

    /**
     * 新增VIP套餐
     */
    @PreAuthorize("@ss.hasPermi('system:package:add')")
    @Log(title = "VIP套餐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVipPackage sysVipPackage) {
        return toAjax(sysVipPackageService.insertSysVipPackage(sysVipPackage));
    }

    /**
     * 修改VIP套餐
     */
    @PreAuthorize("@ss.hasPermi('system:package:edit')")
    @Log(title = "VIP套餐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVipPackage sysVipPackage) {
        return toAjax(sysVipPackageService.updateSysVipPackage(sysVipPackage));
    }

    /**
     * 删除VIP套餐
     */
    @PreAuthorize("@ss.hasPermi('system:package:remove')")
    @Log(title = "VIP套餐", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysVipPackageService.deleteSysVipPackageByIds(ids));
    }
}
